﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Net.Mail;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Text;


/// <summary>
/// Summary description for AllCode
/// </summary>
public class AllCode
{
	public AllCode()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    
    public class Utils
    {
        /*==============================================*/
        //Author: NhanDT 21/12/2010.
        //Email: nhandt@lichsu.vn
        //Website: http://lichsu.vn
        /*==============================================*/
        /// <summary>
        /// Hàm chuyển đổi chuỗi có dấu thành không dấu
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string ConvertToUnSign(string text)
        {
            for (int i = 33; i < 48; i++)
            {
                text = text.Replace(((char)i).ToString(), "");
            }

            for (int i = 58; i < 65; i++)
            {
                text = text.Replace(((char)i).ToString(), "");
            }

            for (int i = 91; i < 97; i++)
            {
                text = text.Replace(((char)i).ToString(), "");
            }

            for (int i = 123; i < 127; i++)
            {
                text = text.Replace(((char)i).ToString(), "");
            }

            text = text.Replace(" ", "-");

            Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");

            string strFormD = text.Normalize(System.Text.NormalizationForm.FormD);
            return regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');
        }

   
        public static string Ngay(DateTime Ngay)
        {

            string t = "";
            t = Ngay.DayOfWeek + " " + Ngay.ToString("dd/MM/yyyy");
            //+ " " + Ngay.TimeOfDay.ToString()
            return t;
        }
        public static string So(double So)
        {
            string s = String.Format("{0:0,0}", So);
            return s;
        }
        public static void SEOTool(System.Web.UI.Page aspPageControl, string canonicalLink, string pageTitle, string metaDescription, string metaKeyword)
        {
            aspPageControl.Title = pageTitle;

            HtmlMeta htmlMeta = new HtmlMeta();
            htmlMeta.Attributes.Add("http-equiv", "Content-Type");
            htmlMeta.Attributes.Add("content", "text/html; charset=utf-8");
            aspPageControl.Header.Controls.Add(htmlMeta);

            htmlMeta = new HtmlMeta();
            htmlMeta.Name = "language";
            htmlMeta.Content = "Vietnamese";
            aspPageControl.Header.Controls.Add(htmlMeta);

            htmlMeta = new HtmlMeta();
            htmlMeta.Name = "description";
            htmlMeta.Content = metaDescription;
            aspPageControl.Header.Controls.Add(htmlMeta);

            htmlMeta = new HtmlMeta();
            htmlMeta.Name = "keywords";
            htmlMeta.Content = metaKeyword;
            aspPageControl.Header.Controls.Add(htmlMeta);

            htmlMeta = new HtmlMeta();
            htmlMeta.Name = "google-site-verification";
            htmlMeta.Content = "9328942384-2349";
            aspPageControl.Header.Controls.Add(htmlMeta);

            htmlMeta = new HtmlMeta();
            htmlMeta.Name = "robots";
            htmlMeta.Content = "index, follow";
            aspPageControl.Header.Controls.Add(htmlMeta);

            htmlMeta = new HtmlMeta();
            htmlMeta.Name = "author";
            htmlMeta.Content = "Thanh Lai (thanhlai@jtechvn.com)";
            aspPageControl.Header.Controls.Add(htmlMeta);

            htmlMeta = new HtmlMeta();
            htmlMeta.Name = "copyright";
            htmlMeta.Content = "Jtech Solutions";
            aspPageControl.Header.Controls.Add(htmlMeta);

            HtmlLink htmlLink = new HtmlLink();
            htmlLink.Attributes["rel"] = "canonical";
            htmlLink.Href = canonicalLink;
            aspPageControl.Header.Controls.Add(htmlLink);
        }
        /// <summary>
        /// Hàm mã hóa mat khẩu kieu SHA1
        /// </summary>
        /// <param name="pass"></param>
        /// <returns></returns>
        public static string Mahoa(string pass)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pass.Trim(), "SHA1");
        }

        /// <summary>
        /// Tao chuoi ngau nhien
        /// </summary>
        /// <returns>1 chuoi dai 15 chu</returns>
        public static string TaoChuoiNgauNhien(int chieudaichuoi)
        {
            string strString = "abcdefghijkl9mnopqrstuvwxyz123456789ABCDEFGHIJKLMNPQRSTUVXYZ156789";
            System.Threading.Thread.Sleep(10);
            Random random = new Random();
            int randomCharIndex = 0;
            char randomChar;
            string captcha = "";
            for (int i = 0; i < chieudaichuoi; i++)
            {
                randomCharIndex = random.Next(0, strString.Length);
                randomChar = strString[randomCharIndex];
                captcha += Convert.ToString(randomChar);
            }
            return captcha;
        }

        
    }
   
}
